#ifndef POKEMONBATTLE_H
#define POKEMONBATTLE_H

#include <QWidget>
#include <QProgressBar>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QMap>
#include <QString>
#include <QListWidget>
#include <qcombobox.h>

// 宝可梦基类
class Pokemon : public QObject
{
    Q_OBJECT
public:
    explicit Pokemon(QObject* parent = nullptr);
    virtual ~Pokemon() = default;

    QString getName() const { return name; }
    int getLevel() const { return level; }
    int getHP() const { return currentHP; }
    int getMaxHP() const { return maxHP; }
    int getAttack() const { return attack; }
    int getDefense() const { return defense; }
    int getSpeed() const { return speed; }

    void takeDamage(int damage);
    bool isFainted() const { return currentHP <= 0; }
    virtual int useSkill(int skillIndex);
    virtual QVector<QString> getSkills() const { return skills; }

protected:
    QString name;
    QString type;
    int level;
    int currentHP;
    int maxHP;
    int attack;
    int defense;
    int speed;
    QVector<QString> skills;
};

// 小火龙类
class Charmander : public Pokemon
{
public:
    explicit Charmander(QObject* parent = nullptr);
    int useSkill(int skillIndex) override;
};

// 妙蛙种子类  
class Bulbasaur : public Pokemon
{
public:
    explicit Bulbasaur(QObject* parent = nullptr);
    int useSkill(int skillIndex) override;
};

// 对战控件主类
class PokemonBattle : public QWidget
{
    Q_OBJECT

public:
    explicit PokemonBattle(QWidget* parent = nullptr);
    void initSpriteMap();
    ~PokemonBattle();

    void setPokemons(Pokemon* playerPokemon, Pokemon* opponentPokemon);
    void startBattle();

private slots:
    void onSkill1Clicked();
    void onSkill2Clicked();
    void onSkill3Clicked();
    void onSkill4Clicked();
    void executeTurn(int playerSkillIndex);

private:
    void updateUI();
    void checkBattleEnd();
    void showBattleMessage(const QString& message);

    // 对战相关成员
    Pokemon* playerPokemon;
    Pokemon* opponentPokemon;
    bool playerTurn;

    // UI 成员
    QProgressBar* playerHPBar;
    QProgressBar* opponentHPBar;
    QLabel* playerNameLabel;
    QLabel* opponentNameLabel;
    QLabel* playerLevelLabel;
    QLabel* opponentLevelLabel;
    QLabel* battleMessageLabel;

    QPushButton* skillButtons[4];
    QLabel* playerSpriteLabel;
    QLabel* opponentSpriteLabel;

    QVBoxLayout* mainLayout;
    QHBoxLayout* battleLayout;
    QHBoxLayout* playerInfoLayout;
    QHBoxLayout* opponentInfoLayout;

    QPushButton* startBatterButton;
    QGridLayout* skillsLayout;
    QComboBox* m_palyerSprites;
    QComboBox* m_opponentSprites;

    //妖怪实例
    QMap<QString, Pokemon*> m_spriteMap;
    Pokemon* CharmanderpPlayer;
    Pokemon* BulbasaurpPlayer;
    Pokemon* CharmanderOppent;
    Pokemon* BulbasaurpOppent;
};

#endif // POKEMONBATTLE_H